using System;
using System.Collections.Generic;
using System.Management.Automation;             //Windows PowerShell namespace.
using System.Text;
using VirtualOps.Base;
using VirtualOps.Vix;

namespace VmWareVix
{
  [Cmdlet(VerbsCommon.Get, "VMMServer", DefaultParameterSetName = "Uri")]
  public class GetVmmServerCommand : PSCmdlet
  {

    [Parameter(Position = 0, //Mandatory=true,
      ParameterSetName = "Uri")]
    public string Uri = "";

    [Parameter] 
    [ValidateNotNullOrEmpty]
    public string Username = "";

    [Parameter] 
    [ValidateNotNull]
    public string Password = "";
    
    
    protected override void ProcessRecord()
    {
      WriteDebug("Connecting to Virtual Machine management system...");
      WriteDebug(String.Format("{0} | {1} | {2} ", Uri, Username, Password));
      WriteObject(GetVmServer());
    }
    
    private VmServer GetVmServer()
    {
      
            VixServer vmServer = VmServer.CreateInstance
                    <VirtualOps.Vix.VixServer>(Uri) as VixServer;
            vmServer.Connect(Username, Password);

            return VmServer.Current;
        
    }
  }
}
